Attribute VB_Name = "mod_varios"
Option Explicit
Public reporte As String
Public fec_desde As Date
Public fec_hasta As Date
Public Backspaced As Boolean

Public Function AutoComplete(ctlComboBox As Control)
'--------- << Called from the _Change event of cboComboBox >> ----------------

'Dim i %, intSel%  ' % is a "shorthand" for Integers
Dim i As Integer
Dim intSel As Integer

    'If this fires in response to a Backspace or Delete, then
    'Exit the function because then you wouldn't be able to backup:
    Select Case (Backspaced Or Len(ctlComboBox.Text) = 0)
        Case True: Backspaced = False: Exit Function
    End Select
    
    With ctlComboBox
        'Run through the available items in a For...Loop and grab
        'the first one that matches the selection:
        For i = 0 To .ListCount - 1
            If InStr(1, .List(i), .Text, vbTextCompare) = 1 Then
                intSel = .SelStart
                .Text = .List(i)
                .SelStart = intSel
                .SelLength = Len(.Text) - intSel
                Exit For
                
            End If
        Next i
    End With

End Function
Sub Actualiza_RS(rs As Object)
  On Local Error Resume Next
  rs.MoveLast
  rs.MoveFirst
  On Local Error GoTo 0
End Sub

Public Property Set limpiar(ByRef frm As Object)
On Error Resume Next
    Dim obj As Object
    For Each obj In frm
        If TypeOf obj Is TextBox Then
            obj = Empty
        End If
        If TypeOf obj Is OptionButton And Val(obj.Tag) <> 1 Then
            obj.Value = False
        End If
        If TypeOf obj Is CheckBox Then
            obj.Value = 0
        End If
        If TypeOf obj Is ComboBox Then
            obj = ""
        End If
        If TypeOf obj Is Image Then
            obj.Picture = LoadPicture("")
        End If
    Next obj
    Set obj = Nothing
On Error GoTo 0
End Property

Public Property Set colorFondo(ByRef frm As Object)
    Dim obj As Object
    For Each obj In frm
        If TypeOf obj Is TextBox Or TypeOf obj Is ComboBox Then
            obj.BackColor = &HE0E0E0
        End If
        If TypeOf obj Is Frame Or TypeOf obj Is Label Or TypeOf obj Is OptionButton Then
            obj.BackColor = &HC0FFFF
        End If
    Next obj
End Property

Public Function YaExiste(ByVal des As String, tabla As String, campo As String) As Boolean
On Local Error GoTo L
    Dim T As New ADODB.Recordset
    
    T.Open "Select " + Trim$(campo) + " from " + Trim$(tabla) + " where " + Trim$(campo) + " = '" + Trim$(des) + "'", con, adOpenForwardOnly, adLockReadOnly
    Actualiza_RS T
    
    If T.RecordCount = 0 Then
        YaExiste = False
        Set T = Nothing
        Exit Function
    End If
    
    YaExiste = True
    Set T = Nothing
    Exit Function
L:
    MsgBox Err.Description, vbCritical
End Function

Public Function Valida_Cuit(nro As String)
    Dim coef As String
    Dim suma As Long
    Dim X As Integer
    Dim coc As Double
    Dim resto As Double
    Dim digito_ver As Integer
    
    If nro <> " " Then
        coef = "5432765432"
        suma = 0
        For X = 1 To 10
            suma = suma + Val(Mid(nro, X, 1)) * Val(Mid(coef, X, 1))
        Next
        coc = suma \ 11
        resto = suma - (coc * 11)
        digito_ver = Val(Right(nro, 1))
        If resto > 1 Then
           resto = 11 - resto
        End If
        If resto <> digito_ver Then
           Valida_Cuit = False
        Else
           Valida_Cuit = True
        End If
    End If
    
End Function


Public Sub pintar_grilla(gri As MSHFlexGrid, col As Integer, filcol As String)
    Dim i, j As Integer
    
    For i = 1 To gri.Rows - 1 'cantfila
        If filcol = "fila" Then
            If gri.TextMatrix(i, col) <> "" Then
                For j = 1 To gri.Cols - 1 'cantcol
                    gri.col = j
                    gri.Row = i
                    gri.CellBackColor = &HC0C0C0
                Next j
            End If
        Else
            gri.col = col
            gri.Row = i
            gri.CellBackColor = &HC0C0C0
        End If
    Next i
End Sub

Public Sub coma(KeyAscii As Integer)
    If KeyAscii = 44 Then
        KeyAscii = 46
    End If
'    If KeyAscii = Asc(".") Then
'        KeyAscii = Asc(",")
'    End If
End Sub

Public Sub formatoDecimal(txt As TextBox)
    txt.Text = Format$(txt, "###.00")
End Sub

Public Sub letrasNo(KeyAscii As Integer)
    If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 46 And KeyAscii <> 13 And KeyAscii <> 8 Then
        KeyAscii = 0
        Beep
    End If
End Sub
